home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6943 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  801 b 

  1. Path: god.bel.alcatel.be!btmpj7!ian
  2. From: ian@rsd.bel.alcatel.be (Ian Ward)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Date: 16 Feb 1996 15:34:19 GMT
  6. Organization: Alcatel Bell Telephone
  7. Distribution: world
  8. Message-ID: <4g285r$gre@btmpjg.god.bel.alcatel.be>
  9. References: <4g0giv$94s@sun132.spd.dsccc.com>
  10. Reply-To: ian@rsd.bel.alcatel.be
  11. NNTP-Posting-Host: btmpj7.rsd.bel.alcatel.be
  12.  
  13. Kevin Cline
  14. > With a bit more thought a log n solution is possible.
  15.  
  16. int last_digit (num)
  17. int num;
  18. { static int tens [4]     = {8,4,2,6};
  19.   static int singles [10] = {1, 1, 2, 6, 4, 2, 2, 4, 2, 8};
  20.   int single = singles [num % 10];
  21.   if (num > 9) single *= tens [(num/10-1) % 4];
  22.   return single % 10;
  23. }
  24.  
  25. I make the 427! last digit 6.
  26.  
  27. ---
  28. Ian Ward's opinions only : ian@rsd.bel.alcatel.be
  29.  
  30.